package com.module.controller;

import com.module.framework.domain.Product;
import com.module.framework.domain.ResponseResult;
import com.module.framework.dto.ProductListDTO;
import com.module.framework.service.ProductService;
import com.module.framework.vo.PageVO;
import com.module.framework.vo.ProductDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
/**
 * @Author JiHuiQin
 * @Date 2022/2/21 22:05
 * @Version 1.0
 */

@RestController
@RequestMapping("/admin/product")
public class ProductController {

	@Autowired
	private ProductService productService;

	@PostMapping("/list")
	public ResponseResult productList(@RequestBody ProductListDTO productListDTO) {
		PageVO pageVO = productService.productList(productListDTO);
		return ResponseResult.okResult(pageVO);
	}

	@PostMapping("/add")
	public ResponseResult addProduct(@RequestParam(value = "file", required = false) MultipartFile file, String data) throws IOException {
		productService.addProduct(file, data);
		return ResponseResult.okResult();
	}

	@GetMapping("/info")
	public ResponseResult getProductInfo() {
		ProductDetailVO productInfo = productService.getProductInfo(1);
		return null;
	}

	@PostMapping("/update")
	public ResponseResult updateProduct(@RequestBody Product product) {
		productService.updateProduct(product);
		return ResponseResult.okResult();
	}

	@GetMapping("/delete")
	public ResponseResult deleteProduct(Integer id) {
		productService.deleteProduct(id);
		return ResponseResult.okResult();
	}

}
